package cn.cntv.app.ipanda.home.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

public class BannerAdapter extends PagerAdapter {
	private List<View> mList;

	public BannerAdapter(List<View> views) {
		mList = views;
	}
	
	public void setList(List<View> list) {
		mList = list;
		notifyDataSetChanged();
	}
	
	/**
	 * Return the number of views available.
	 */
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}
	
	/**
	 * Remove a page for the given position.
	 * 滑动过后就销毁 ，销毁当前页的前一个的前一个的页！
	 * instantiateItem(View container, int position)
	 * This method was deprecated in API level . Use instantiateItem(ViewGroup, int)
	 */
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		// TODO Auto-generated method stub
		container.removeView(mList.get(position));
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub
		return arg0==arg1;
	}
	
	/**
	 * Create the page for the given position.
	 */
	@Override
	public Object instantiateItem(final ViewGroup container, final int position) {
		container.removeView(mList.get(position));
		container.addView(mList.get(position));
		return mList.get(position);

	}
}
